﻿@model View_Member
@{
    ViewBag.Title = "生成邀请码";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new View_Member();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    int count = 0;
}

<form id="S_Form" action="@Url.Action("buildcode", "account")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>快速一键生成邀请码，不同等级可生成邀请码数量不通</h5>
                <input type="hidden" value="@viewModel.uid" name="uid" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">代购编号<em>*</em></td>
            <td>
                @Model.replace_buyer_NO
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">会员名称<em>*</em></td>
            <td>
                @Model.member_name
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">用户等级<em>*</em></td>
            <td>
                @Model.member_level_name
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">邀请码上限<em>*</em></td>
            <td>
                @Model.invite_limit
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">已生成数量<em>*</em></td>
            <td>
                @{
                    count = dbcontext.ADZ_InviteCode.Where(t => t.uid == viewModel.uid).Count();
                    @count
                }
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <div><span id="spMsg"></span></div>
                @if (viewModel.uid > 0)
                {
                    if (count < Model.invite_limit)
                    {
                        <button type="submit" class="btn btn-primary">一键生成</button>
                    }
                }
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>

        </tr>
    </table>
    <script>
        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () { window.location.reload(); });
                        });
                    }
                });
            });
        });
    </script>
</form>
